home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / odoors41.zip / EX_MUSIC.C < prev    next >
C/C++ Source or Header  |  1993-04-05  |  5KB  |  112 lines

  1. /* EX_MUSIC.C - Example program that demonstrates how to play "ANSI" music and
  2.  *              sound effects in an OpenDoors door.
  3.  */
  4.  
  5.  
  6. #include "opendoor.h"                    /* Required in any OpenDoors program */
  7.  
  8.  
  9. void play_sound(char *string);          /* Functions for playing "ANSI" music */
  10. char test_sound(void);
  11.  
  12. char sound_enabled=TRUE;     /* Variable indicates whether or not sound is on */
  13.  
  14.  
  15.  
  16. main()                                     /* Program's execution begins here */
  17.    {                                          /* Display introductory message */
  18.    od_printf("`BRIGHT WHITE`This is a simple door program that will play the song Happy Birthday\n\r");
  19.    od_printf("tune on the remote system, if the user's terminal program supports ANSI\n\r");
  20.    od_printf("music. Music is not played on the local speaker, as BBS system operators\n\r");
  21.    od_printf("do not wish to have the BBS computer making sounds at any time of the day\n\r");
  22.    od_printf("or night. However, the program can easily be modified to also echo sound to\n\r");
  23.    od_printf("the local speaker.\n\r\n\r");
  24.  
  25.  
  26.    test_sound();        /* Test whether user's terminal supports "ANSI" music */
  27.  
  28.  
  29.    od_clr_scr();                                          /* Clear the screen */
  30.    od_printf("`BRIGHT RED`Happy Birthday!\n\r\n\r");     /* Display a message */
  31.  
  32.  
  33.                          /* If "ANSI" sound is available, play Happy Birthday */
  34.    play_sound("MBT120L4MFMNO4C8C8DCFE2C8C8DCGF2C8C8O5CO4AFED2T90B-8B-8AFGF2");
  35.    play_sound("00m");                   /* Reset sound after finished playing */
  36.  
  37.                                                             /* Display prompt */
  38.    od_printf("`BRIGHT GREEN`Press any key to return to BBS...\n\r");
  39.    od_get_key(TRUE);                          /* Wait for user to press a key */
  40.    od_exit(10, FALSE);                                           /* Exit door */
  41.    }
  42.  
  43.  
  44.  
  45. /* Function to test whether the user's terminal program supports ANSI music.
  46.  * You can either do this every time the user uses your door, or only the first
  47.  * time they use the door, saving the result in a data file.
  48.  */
  49.  
  50. char test_sound(void)
  51.    {
  52.    char response;            /* Variable to store user's response to question */
  53.  
  54.                                        /* Display description of test to user */
  55.    od_printf("`BRIGHT WHITE`We need to know whether or not your terminal program supports ANSI music.\n\r");
  56.    od_printf("In order to test this, we will send a short ANSI music sequence. We will then\n\r");
  57.    od_printf("ask whether or not you heard any sound.\n\r");
  58.    od_printf("`BRIGHT GREEN`Press any key to begin this test... ");
  59.  
  60.    od_get_key(TRUE);                 /* Wait for user to press a key to begin */
  61.    od_printf("\n\r\n\r");
  62.  
  63.    sound_enabled=TRUE;                            /* Temporarily enable sound */
  64.    play_sound("MBT120L4MFMNO4C8C8DC");            /* Send sound test sequence */
  65.    play_sound("00m");                      /* Reset sound after finished test */
  66.  
  67.    od_clr_scr();             /* Clear screen and ask whether user heard sound */
  68.    od_printf("`BRIGHT GREEN`Did you just hear sound from your speaker? (Y/n)");
  69.    do response=od_get_key(TRUE); while (response!='y' && response!='n' && response!='Y' && response!='N');
  70.    od_printf("\n\r\n\r");
  71.  
  72.                         /* Set ANSI music on/off according to user's response */
  73.    return (sound_enabled = (response=='y' || response=='Y'));
  74.    }
  75.  
  76.  
  77.  
  78. /* Function to play "ANSI" music or sound effects. The play_sound() function
  79.  * can be called with a string of 0 to 250 characters. The caracters of the
  80.  * string define what sounds should be played on the remote speaker, as
  81.  * follows:
  82.  *
  83.  *      A - G       Musical Notes
  84.  *      # or +      Following A-G note means sharp
  85.  *      -           Following A-G note means flat
  86.  *      <           Move down one octave
  87.  *      >           Move up one octave
  88.  *      .           Period acts as dotted note (extend note duration by 3/2)
  89.  *      MF          Music Foreground (pause until finished playing music)
  90.  *      MB          Music Background (continue while music plays)
  91.  *      MN          Music note duration Normal (7/8 of interval between notes)
  92.  *      MS          Music note duration Staccato
  93.  *      ML          Music note duration Legato
  94.  *      Ln          Length of note (n=1-64, 1=whole note, 4=quarter note, etc)
  95.  *      Pn          Pause length (same n values as Ln above)
  96.  *      Tn          Tempo, n=notes/minute (n=32-255, default n=120)
  97.  *      On          Octave number (n=0-6, default n=4)
  98.  */
  99.  
  100. void play_sound(char *string)
  101.    {
  102.    char musicString[255]={27,'[','\0'};        /* Beginning of music sequence */
  103.  
  104.    if(!sound_enabled) return;                /* Abort if sound is not enabled */
  105.  
  106.    strcat(musicString,string);         /* Generate sequence to send to remote */
  107.    musicString[strlen(musicString)+1]='\0';
  108.    musicString[strlen(musicString)]=0x0e;
  109.  
  110.    od_disp(musicString,strlen(musicString),FALSE);   /* Transmit the sequence */
  111.    }
  112.